<?php 
	ob_start(); session_start(); 
	require_once('adminpanel/config/setting.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration</title>
</head>
<style>
	.topmenu{
		font-family:arial;
		font-size:14px;
		color:#FFFFFF;
		text-decoration:none;
	}
	.topmenu:hover{
		font-family:arial;
		font-size:14px;
		color:#FFFFFF;
		text-decoration:underline;
	}
</style>

<?php 
		$memberid = $_SESSION['memberid'];
		$result = mysql_query("select * from tbl_members where id='$memberid' limit 1") or die (mysql_error());
		if($row = mysql_fetch_array($result)){
			$id = $row['id'];
			$username = $row['username'];
			$firstname = $row['firstname'];
			$lastname = $row['lastname'];
			$email = $row['email'];
			$password = $row['password'];
			$gender = $row['gender'];
			$birthday = $row['birthday'];
		}
		$warning = '';		
		if($_POST['deactivate']){
			$datedeleted = time();
			$id = $_POST['nid'];
			mysql_query("update tbl_members set active='0',datedeleted='".$datedeleted."' where id='$id' limit 1") or die (mysql_error());
			$warning = 'Account Deleted Successfully!';
		}
		if($_POST['regsubmit']){
			$id = $_POST['nid'];
			$firstname = $_POST['firstname'];
			$lastname = $_POST['lastname'];
			$email = $_POST['email'];
			$password = $_POST['password'];
			$gender = $_POST['gender'];
			mysql_query("update tbl_members set firstname='".$firstname."', lastname='".$lastname."', email='".$email."', password='".$password."', 
			gender='".$gender."'  where id='$id' limit 1") or die (mysql_error());				
			$warning = 'Updated Successfully!';
		}
		if($_POST['deactivate']){
			$id = $_POST['nid'];
			$firstname = $_POST['firstname'];
			$lastname = $_POST['lastname'];
			$email = $_POST['email'];
			$password = $_POST['password'];
			$gender = $_POST['gender'];
			mysql_query("delete tbl_members where id='$id'") or die (mysql_error());				
			$warning = 'Delete Successfully!';
		}
		
		
?>
<body style="margin:0px; background-color:#f1f1f1">
	<div id="header" style="background:url(images/top-bg.png) repeat-x; " align="center">
<div style="width:982px;" >
        	<div style="padding-top:30px; padding-right:20px; color:#FFFFFF" align="right">
            	<img src="images/the-century-logo.png" style="top:20px; margin-left:50px;" align="left" />
            	<a href="index.php" class="topmenu">Home</a> &nbsp; | &nbsp; 
                <a href="about-us.php" class="topmenu">About Us</a> &nbsp; | &nbsp; 
                <a href="questions.php" class="topmenu">Questions</a> &nbsp; | &nbsp; 
                <a href="reservation.php" class="topmenu">Reservation</a> &nbsp; | &nbsp; 
				<a href="menu.php" class="topmenu">Menu</a> &nbsp; | &nbsp; <?php if(!($_SESSION['username'])){?>
                <a href="signup.php" class="topmenu">Signup</a><?php } else {?>
                <a href="logout.php" class="topmenu">Logout</a><?php }?>
                <br /><br/>
                <?php 
                include('login.php');
				?>            
            </div>
        	<img src="images/top-gradient.png" />
            <div style="position:absolute; top:200px; margin-left:50px; font-size:24px; color:#F00 ">My Account</div>
        </div>    </div>
	<div id="body" align="center">
    	<div style="width:982px" align="center">
            <div style="width:900px;margin-left:0px; line-height:18px; font-family:verdana; font-size:12px; color:#666" align="left" >
            	<?php if($_GET['page'] == 'Thank You') { echo '<span style="font-size:18px; color:red">Registration Successfully Submitted, Thanks You.</span>'; } else {?>
            	<form name="regform" method="post">
                	<input name="nid" type="hidden" value="<?=$id;?>" />
				<table width="600px" cellspacing="2px" cellpadding="5px" style="border:solid 1px #d0e2e6" bgcolor="#FFFFFF"  >
						<tr>
								<td >
									Username: <br />
									<input name="username" type="text" style="width:150px;" readonly="readonly" value="<?=$username?>" />
								</td>
								<td>
								<span style="color:#ed8103;">&bull;</span><i style="font-size:11px;"> Required fields.</i><br>
								<div align="left" style="color:#ed8103"><b><?=$dupmessage?></b></div>				
								</td>
							</tr>
							<tr>
								<td width="259" >
									First Name: <span style="color:#ed8103">&bull;</span><br />
									<input name="firstname" type="text" style="width:250px;"  value="<?=$firstname?>" />
							  </td>
								<td width="313" >
									Last Name: <span style="color:#ed8103">&bull;</span><br />
									<input name="lastname" type="text"  style=" width:250px;"  value="<?=$lastname?>" />
							  </td>
							</tr>
							<tr>
								<td >
									Your Email Address: <span style="color:#ed8103">&bull;</span><br />
									<input name="email" style=" width:250px;"  type="text" value="<?=$email?>" />
								</td>
								<td >
									I am: <span style="color:#ed8103">&bull;</span><br />
                                    	
                                    <input name="sgender" type="radio" onclick="checkgender(1)" <?php if($gender=='M') echo'checked' ?> /> Male &nbsp;&nbsp;&nbsp; <input name="sgender" onclick="checkgender(2)" type="radio"  <?php if($gender=='F') echo'checked' ?> /> Female
									<input name="gender" type="hidden" value=""/>
									
									
									
								</td>
							</tr>
							<tr>
								<td>
									Password: <span style="color:#ed8103">&bull;</span><br />
									<input name="password" style="width:250px;"  type="text"  value="<?=$password?>"/>
								</td>
								
							</tr>
							<tr>
								<td style="color:#F00" ><?=$warning;?></td>
								<td></td>								
							</tr>
							<tr>
								<td height="50px" colspan="2" align="left">
								<input type="submit" name="regsubmit" value="Update My Account" onclick="return validateField();" style="height:40px;" /> &nbsp; &nbsp; &nbsp;
                                <input type="submit" name="deactivate" value="Deactivate My Account" onclick="return deleteAccount();" style="height:40px;" />
								</td>
							</tr>
							
						</table>           
                        </form>
                        <?php } ?>
                     </div>
        </div>
    </div>
    <div id="footer" style="background:url(images/btm-bg.png) repeat-x; height:166px" align="center">
    	<div style="width:982px">
        	<div style="height:40px"></div>
        	<img src="images/btm-gradient.png" />
        </div>
    		
    </div>
<script>
	function checkgender(g){
		var ngender = '';
		if(g==1){
			document.regform.gender.value = 'M';
		}
		if(g==2){
			document.regform.gender.value = 'F';
		}
		
	}
	
	function validateField(){
		return true;
		emptyfield = '', iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		
		if(document.regform.firstname.value.trim()==''){
			emptyfield += ' > First Name \n';
			alert("sdfhggfdhgjkdfg");
		}
		if(document.regform.lastname.value.trim()==''){
			emptyfield += ' > Last Name \n';
		}
		if(document.regform.email.value.trim()==''){
			emptyfield += ' > Email Address \n';
		}
		if(document.regform.email.value != document.regform.confirmemail.value){
			emptyfield += ' > Email mismatch please re-enter again \n';
		}
		if(document.regform.gender.value.trim()==''){
			emptyfield += ' > Gender \n';
		}
		if(document.regform.nmonth.value =='' || document.regform.nday.value=='' || document.regform.nyear.value==''){
			emptyfield += ' > Birthday\n';
		}
		
		if(document.regform.password.value==null ){
			emptyfield += ' > Password \n';
			alert("sdkfjhsdfjh");
		}
		
		
		
	  for (var i = 0; i < document.regform.username.value.length; i++) {
		if (iChars.indexOf(document.regform.username.value.charAt(i)) != -1) {
		alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
		return false;
		}
	  }		
		
		if (document.regform.email.value.length > 0) {
		  i=document.regform.email.value.indexOf("@")
		  j=document.regform.email.value.indexOf(".",i)
		  k=document.regform.email.value.indexOf(",")
		  kk=document.regform.email.value.indexOf(" ")
		  jj=document.regform.email.value.lastIndexOf(".")+1
		  len=document.regform.email.value.length
		
		if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
		} else {
		  alert("Please enter correct email address.\n" +
		  document.regform.email.value + " is invalid.");
		  return false;
		  }
		}		
		
		if(emptyfield==''){
			return true;				
		}else{
			alert('Please complete required fields: \n'+emptyfield);
			return false;
		}
		
	}
	
	function deleteAccount(){
		var answer = confirm('Are you sure you want to delete your account?');
		if(answer){return true;}else{
			return false;			
		}
	}
	
	

</script>    
</body>
</html>